// pages/law/clist/index.js
import util from '../../../utils/util';


Page({
  data:{
    lawList: null,
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数

    this.setData({
      name: options.name
    });

    wx.setNavigationBarTitle({
      title: this.data.name
    });

    var _appInstance = getApp();
    var _globalData = _appInstance.globalData;
    this.setData({
      switchForVerify: !!_globalData.switchForVerify || false
    });

    var that = this;

    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    });

    // 获取列表
    wx.request({
      url: `${getApp().globalData.serverHost}/wx/bd/getCategories`, //仅为示例，并非真实的接口地址
      data: {pid: options.id},
      method: "post",
      header: {
          'content-type': 'application/json'
      },
      success: function(res) {
        var _data = res.data || [];
        for(var i=0; i<_data.length; i++){
          for(var j=0; j<_data[i].detail.length; j++){
              _data[i].detail[j].publishTime = util.formatCommonShortTime(_data[i].detail[j].publishTime);
              _data[i].detail[j].effectiveTime = util.formatCommonShortTime(_data[i].detail[j].effectiveTime);
          }
        }
        wx.hideToast();
        that.setData({
          lawList: res.data || []
        });

        // 在适合的场景显示插屏广告
        if (that.interstitialAd) {
          that.interstitialAd.show().catch((err) => {
            console.error(err)
          })
        }
      },
      fail: function(res){
        console.log(res);
      }
    });

    // 在页面中定义插屏广告
    this.interstitialAd = null
    // 在页面onLoad回调事件中创建插屏广告实例
    if (wx.createInterstitialAd) {
      this.interstitialAd = wx.createInterstitialAd({
        adUnitId: 'adunit-8202ae2587610d39'
      })
      this.interstitialAd.onLoad(() => {})
      this.interstitialAd.onError((err) => {})
      this.interstitialAd.onClose(() => {})
    }
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})